const order = require("../service/order");

const orderadd = async (ctx) => {
  let res = await order.orderadd(ctx.request.body);
  if (res.affectedRows) {
    return (ctx.body = {
      code: 20000,
      data: res,
      msg: "添加成功",
    });
  } else {
    return (ctx.body = {
      code: 40001,
      data: "",
      msg: "添加失败",
    });
  }
};

const orderlist = async (ctx) => {
  let res = await order.orderlist(ctx.query);
  if (res.length) {
    return (ctx.body = {
      code: 20000,
      data: res,
      msg: "查询成功",
    });
  } else {
    return (ctx.body = {
      code: 40001,
      data: "",
      msg: "查询失败",
    });
  }
};

const orderdetail = async (ctx) => {
  let res = await order.orderdetail(ctx.query);
  if (res.length) {
    return (ctx.body = {
      code: 20000,
      data: res,
      msg: "查询成功",
    });
  } else {
    return (ctx.body = {
      code: 40001,
      data: "",
      msg: "查询失败",
    });
  }
};

module.exports = {
  orderadd,
  orderlist,
  orderdetail,
};
